﻿<?php
/**
 * 显示管理用户详细界面
 *
 * @author kinet <380511703@qq.com>
 * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
 */

session_start();
require_once( 'path.php' );
require_once( SOJ_ROOT.'/include/function/lib.php');

$tpl = new my_smarty();

//若未登录,则重定向到登录界面
if( empty($_SESSION['admin']) ){

	$_SESSION['success_message'] = 'do not login yet , '.$_SESSION['admin'];
	header( 'Location:../manager/manager_login.php' );
	exit ;
}
$request = $_GET;

if( empty( $request['name']) ){
	//用户名,直接跳转到user页面
	header( 'Location:../manager/manager_user.php' );
	exit ;
}else{
	$username = $request['name'];
}

//处理由其他页面保存在会话中的错误信息
if( !empty($_SESSION['errors']) ){

	$tpl->assign( 'errors' , $_SESSION['errors']  );
	//清除之前的错误信息
	unset( $_SESSION['errors'] );
}
$tpl->assign('admin', $_SESSION['admin']);

try{
	$db = db_connect();
	$user = new user_process( $db ) ;
	$user->load( 'username' , $username );
    $user_profile=new user_profile_process( $db ) ;
    $user_profile->load('username' , $username);
    $user_judge_statistics=new user_judge_statistics_process( $db ) ;
    $user_judge_statistics->load( 'username' , $username );
	//@todo 是传入整个数组 由模板判断如何显示 还是传入单独的值?
	//可以由db_obj.class提供一个get_all()方法返回所有的值



	$username= $username ;
	$passwd = $user->get('passwd');
	$role = $user->get('role');
	$email = $user->get('email');
	$signup_time = $user->get('signup_time');
	$last_signin_time = $user->get('last_signin_time');
	$last_signin_ipadd = $user->get('last_signin_ipadd');
	$nick =  $user_profile->get('nick');
	$sex =  $user_profile->get('sex');
	$location = $user_profile->get('location');
	$motto = $user_profile->get('motto');
	$submit_times = $user_judge_statistics->get('submit_times');
    $accepted_times=$user_judge_statistics->get('accepted_times');
    $wrong_answer_times=$user_judge_statistics->get('wrong_answer_times');
	$presentation_times=$user_judge_statistics->get('presentation_times');
	$compilation_error_times=$user_judge_statistics->get('compilation_error_times');
    $time_exceeded_times=$user_judge_statistics->get('time_exceeded_times');
	$memory_exceeded_times=$user_judge_statistics->get('memory_exceeded_times');
    $output_exceeded_times=$user_judge_statistics->get('output_exceeded_times');
    $runtime_error_times=$user_judge_statistics->get('runtime_error_times');
    $compile_time_over=$user_judge_statistics->get('compile_time_over');

	$tpl->assign( 'username' , $username );
	$tpl->assign( 'passwd' , $passwd );
	$tpl->assign( 'role' , $role );
	$tpl->assign( 'email' , $email );
	$tpl->assign( 'signup_time' , $signup_time);
	$tpl->assign( 'last_signin_time' , $last_signin_time );
	$tpl->assign( 'last_signin_ipadd' , $last_signin_ipadd );
	$tpl->assign( 'nick' , $nick );
	$tpl->assign( 'sex' , $sex );
	$tpl->assign( 'location' , $location );
	$tpl->assign( 'motto' , $motto );
	$tpl->assign( 'submit_times' , $submit_times );
	$tpl->assign( 'accepted_times' , $accepted_times );
    $tpl->assign( 'wrong_answer_times' ,  $wrong_answer_times );
    $tpl->assign( 'presentation_times' , $presentation_times );
    $tpl->assign('compilation_error_times' ,$compilation_error_times );
	$tpl->assign('time_exceeded_times' ,$time_exceeded_times );
	$tpl->assign('memory_exceeded_times' ,$memory_exceeded_times );
    $tpl->assign('output_exceeded_times' ,$output_exceeded_times );
    $tpl->assign('runtime_error_times' ,$runtime_error_times );
    $tpl->assign('compile_time_over' ,  $compile_time_over );

	$tpl->display('manager_user_detail.tpl');
	}catch(Exception $e){
		echo $e->getMessage();
}


